package com.lanlian.cayman.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lanlian.cayman.R;
import com.lanlian.commonlib.bean.EntrustDetailsInfo;
import com.lanlian.utillib.DateUtils;

import java.util.Date;
import java.util.List;

/**
 * <pre>
 *     author : huxiaobo
 *     e-mail : huxiaobo@xlanlian.com
 *     date   : 2018/8/15 16:55
 *     desc   : 委托明细Adapter
 *     version: 1.0
 * </pre>
 */
public class TradeDetailsEntrustAdapter extends BaseQuickAdapter<EntrustDetailsInfo, BaseViewHolder> {

    public TradeDetailsEntrustAdapter(int layoutResId, @Nullable List<EntrustDetailsInfo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, EntrustDetailsInfo item) {
        helper.setBackgroundColor(R.id.lay_position, (helper.getLayoutPosition() + 1) % 2 == 0 ?
                mContext.getResources().getColor(R.color.color_bg_text_view_style2) :
                mContext.getResources().getColor(R.color.color_bg_text_view_style3));
        Date date = DateUtils.StringToDate(item.getdDatetime());
        String time = DateUtils.DateToString(date, "yyyy-MM-dd\nHH:mm:ss");
        helper.setText(R.id.tv_contract_name, item.getContractName())
                .setText(R.id.tv_order_no, item.getlOrderNo().toString())
                .setText(R.id.tv_direction, "1".equals(item.getcOrderDirection()) ? "买" : "卖")
                .setText(R.id.tv_currency_type, item.getCurrency())
                .setText(R.id.tv_status, getStatus(item.getcOrderStatus()))
                .setText(R.id.tv_order_price, item.getcPriceType() == 1 ? "市价" : item.getEnOrderPrice().toString())
                .setText(R.id.tv_deal_jj, item.getEnAvgPrice() == 0 ? "--" : item.getEnAvgPrice().toString())
                .setText(R.id.tv_deal_amount, item.getLdealAmount() == 0 ? "--" : item.getLdealAmount().toString())
                .setText(R.id.tv_order_amount, item.getlOrderAmount() == 0 ? "--" : item.getlOrderAmount().toString())
                .setText(R.id.tv_type, getOrderType(item.getcOrderType()))
                .setText(R.id.tv_time, time);
        switch (item.getcOrderDirection()) {
            case "1":
                helper.setTextColor(R.id.tv_direction, mContext.getResources().getColor(R.color.color_T7));
                helper.setText(R.id.tv_direction, "买");
                break;
            case "2":
                helper.setTextColor(R.id.tv_direction, mContext.getResources().getColor(R.color.color_T8));
                helper.setText(R.id.tv_direction, "卖");
                break;
            case "3":
                helper.setTextColor(R.id.tv_direction, mContext.getResources().getColor(R.color.color_text_style1));
                helper.setText(R.id.tv_direction, "平");
                break;
            default:
                break;
        }
        helper.setTextColor(R.id.tv_status, mContext.getResources().getColor(getStatusColor(item.getcOrderStatus())));
    }

    private String getStatus(String status) {
        switch (status) {
            case "1":
            case "2":
            case "3":
            case "4":
                return "委托中";
            case "5":
                return "报单失败";
            case "6":
                return "部分成交";
            case "7":
                return "已成交";
            case "8":
                return "部分撤销";
            case "9":
                return "已撤销";
            case "a":
            case "A":
                return "撤销中";
            default:
                return "";
        }
    }

    private int getStatusColor(String status) {
        switch (status) {
            case "1":
            case "2":
            case "3":
            case "4":
                return R.color.color_K3;
            case "5":
                return R.color.color_T7;
            case "7":
                return R.color.color_K4;
            case "6":
            case "8":
            case "9":
            case "a":
            case "A":
                return R.color.color_text_style1;
            default:
                return 0;
        }
    }

    private String getOrderType(String status) {
        switch (status) {
            case "1":
                return "APP下单";
            case "2":
                return "跟单";
            case "3":
                return "止盈止损";
            case "4":
                return "系统强平";
            case "6":
                return "到点强平";
            case "5":
                return "PC下单";
            case "7":
                return "管理员强平";
            case "8":
                return "APP平仓";
            case "9":
                return "PC平仓";
            case "10":
                return "管理员平仓";
            case "11":
                return "到期强平";
            default:
                return "APP下单";
        }
    }

}
